<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:t="http://myfaces.apache.org/tomahawk">
    <f:loadBundle basename="messages" var="msgs"/>
    <body>
        <ui:composition template="/template.xhtml">
            <ui:define name="customs">
                <script type="text/javascript" src="js/autocomplete.js" language="javascript"/>
                <script type="text/javascript" src="#{contextPath}/counting/counting.js"  language="javascript"/> 
            </ui:define>
            <ui:define name="title">Verificación de Conteo Paralelo</ui:define>
            <ui:define name="main-content">
                <h:form id="docForm" name="docForm">
                    <center><h:messages id="errorMessages" styleClass="messages" layout="table"/></center>
                    <hr/>
                    <table id="parameters" width="90%" align="center">
                        <tr>
                            <td width="70%">
                                <table id="tabParameters" align="left" width="100%">
                                    <tr align="left">
                                        <td>Municipio: </td>
                                        <td>
                                            <h:selectOneMenu id="townsCombo" value="#{modifyRapidBean.town}" class="SelectOption"
                                                             onchange="this.form.submit();" valueChangeListener="#{modifyRapidBean.processTownChange}">
                                                <t:selectItems id="townOption" value="#{modifyRapidBean.towns}" var="town" itemLabel="#{town.name}" itemValue="#{town}"/>
                                                <f:converter converterId="objconverter"/>
                                            </h:selectOneMenu>
                                            <br/>
                                            <h:outputText id="townName" value=""/>
                                        </td>
                                    </tr>
                                    <tr align="left">
                                        <td>Centro: </td>
                                        <td>
                                            <h:selectOneMenu id="ballotsCombo" value="#{modifyRapidBean.ballotCentre}" class="SelectOption">
                                                <t:selectItems id="ballotOption" value="#{modifyRapidBean.ballots}" var="ballotCentre" itemLabel="#{ballotCentre.description}" itemValue="#{ballotCentre}"/>
                                                <f:converter converterId="objconverter"/>
                                            </h:selectOneMenu>
                                            <br/>
                                            <h:outputText id="ballotDesc" value=""/>
                                        </td>
                                    </tr>
                                    <tr align="left">
                                        <td>Jrv: </td>
                                        <td>
                                            <input type="text" id="autocomplete_jrv" name="autocomplete_jrv"/>
                                        </td>
                                    </tr>
                                    <div id="autocomplete_choices" class="autocomplete"></div> 
                                </table>
                            </td>
                            <td width="30%">
                                <table id="tabCalculations" align="left" width="100%">
                                    <thead>
                                        <tr align="center"><th>Suma de Votos</th></tr>
                                    </thead>
                                    <tr>
                                        <td align="left">Depositados Calculados</td>
                                        <td><h:outputText id="calcDepositedVotes" size="8" value="#{modifyRapidBean.document.calcDepositedVotes}"/></td>
                                    </tr>
                                    <tr>
                                        <td align="left">Válidos Calculados</td>
                                        <td><h:outputText id="calcValidVotes" size="8" value="#{modifyRapidBean.document.validVotes}"/></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                    <table align="center">
                        <td><h:commandButton title="Buscar" action="#{modifyRapidBean.search}" image="images/Search.png"/></td>
                        <td><h:commandButton title="Reiniciar" action="#{modifyRapidBean.reset}" image="images/Redo.png"/></td>
                        <td><h:commandButton title="Guardar" action="#{modifyRapidBean.modify}" image="images/Save.png" onclick="return validations();"/></td>
                    </table>
                    <br/>
                    <table width="70%" align="center">
                        <tr align="center">
                            <th>PLC</th>
                            <th>FSLN</th>
                            <th>ALN</th>
                            <th>APRE</th>
                            <th>APLI</th>
                        </tr>
                        <tr>
                            <td align="center">1</td>
                            <td align="center">2</td>
                            <td align="center">9</td>
                            <td align="center">10</td>
                            <td align="center">13</td>
                        </tr>
                        <tr>
                            <td align="center"><img src="images/BANDERA_PLC.jpg" width="75" height="40"/></td>
                            <td align="center"><img src="images/BANDERA_FSLN.jpg" width="75" height="40"/></td>
                            <td align="center"><img src="images/BANDERA_ALN.jpg" width="75" height="40"/></td>
                            <td align="center"><img src="images/BANDERA_APRE.jpg" width="75" height="40"/></td>
                            <td align="center"><img src="images/BANDERA_APLI.jpg" width="75" height="40"/></td>
                        </tr>
                        <tr>
                            <td align="center"><h:inputText id="votePlc" size="12" value="#{modifyRapidBean.votePlc}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                            <td align="center"><h:inputText id="voteFsln" size="12" value="#{modifyRapidBean.voteFsln}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                            <td align="center"><h:inputText id="votePrn" size="12" value="#{modifyRapidBean.votePrn}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                            <td align="center"><h:inputText id="voteAln" size="12" value="#{modifyRapidBean.voteAln}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                            <td align="center"><h:inputText id="voteAc" size="12" value="#{modifyRapidBean.voteAc}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                        </tr>
                    </table>
                    <br/>
                    <table width="80" align="center">
                        <tr width="50%" align="center">
                            <th>Votos Depositados</th>
                            <th>Votos Válidos</th>
                            <th>Votos Nulos</th>
                        </tr>
                        <tr width="50%">
                            <td><h:inputText id="depositedVotes" value="#{modifyRapidBean.document.depositedVotes}" onchange="return calcNulls();"/></td>
                            <td><h:inputText id="validVotes" value="#{modifyRapidBean.document.validVotes}" onchange="return calcNulls();"/></td>
                            <td><h:inputText id="nullVotes" value="#{modifyRapidBean.document.nullVotes}" onchange="return calcNullSingle();"/></td>
                        </tr>
                    </table>
                    <br/>
                    <table width="50" align="center">
                        <tr>
                            <td align="left">Impugnada</td>
                            <td><h:selectBooleanCheckbox title="Impugnada" value="#{modifyRapidBean.document.impugnada}"/></td>
                        </tr>
                    </table>
                    <br/>
                    <h:inputHidden id="operation" value="MODIFICACION"/>
                    <h:inputHidden id="counting" value="#{modifyRapidBean.counting}"/>
                    <h:inputHidden id="jrvHidden" value="#{modifyRapidBean.jrv}">
                        <f:converter converterId="objconverter"/>
                    </h:inputHidden>
                    <c:if test="#{modifyRapidBean.document != null}">
                        <h:inputHidden id="documentId" value="#{modifyRapidBean.document.id}"/>
                        <c:if test="#{modifyRapidBean.document.jrv != null}">
                            <h:inputHidden id="jrvCodeHidden" value="#{modifyRapidBean.document.jrv.code}"/>
                        </c:if>
                    </c:if>
                    <h:inputHidden id="ballotHidden" value="#{modifyRapidBean.ballotCentre}">
                        <f:converter converterId="objconverter"/>
                    </h:inputHidden>
                </h:form>
                <script language="javascript">
                    cleanup();
                </script>
            </ui:define>
            <ui:define name="news-content">
                <span class="smalltitle">Registro</span><br/><br />
                
                <span class="smallredtext">Total Registrados</span><br />
                <span class="bodytext">
                    <c:if test="#{currentUser != null}">
                        #{modifyRapidBean.totalInserted} JRVs
                    </c:if>
                </span><br/><br/>
                <span class="smallredtext">Último Insertado</span><br />
                <span class="bodytext">
                    <c:if test="#{currentUser != null}">
                        Jrv: #{modifyRapidBean.lastInsertedDocument.jrv.code}
                        <br/>
                        Votos: #{modifyRapidBean.lastInsertedDocument.calcDepositedVotes}
                    </c:if>
                </span><br/>
            </ui:define>
        </ui:composition>
    </body>
</html>